//디버그창 처럼 메세지 출력
var PrintMessage = function () {

	this.debug = null;
	
	if(this.debug === null) {
		var textarea = document.createElement('textarea');
		textarea.setAttribute('style', 'width:100%; height:300px;');
		textarea.setAttribute('id', 'data-debug');
		document.body.appendChild(textarea);
		this.debug = document.getElementById('data-debug');
	} 
	
	this.print = function(message) {

		if(typeof message !== 'string') {
			return;
		}
		
		var addmsg = document.createTextNode(new Date().toString() + ' : ' + message + '\n');
		this.debug.appendChild(addmsg);
	};
};

var EventObserver = function() {
	this.handlers = {};
	
	this.addHandler = function (type, handler) {
		if(typeof this.handlers[type] === 'undefined') {
			this.handlers[type] = [];
		}
		this.handlers[type].push(handler);
	};
	
	this.removeHandler = function (type, handler) {
		var handlers = this.handlers[type];
		for(var i = 0, len = handlers.length; i < len; i++) {
			if(handlers[i] === handler) {
				handlers.splice(i, 1);
				break;
			}
		}
	};
	
	this.fire = function(type){
		for(var i = 0, len = this.handlers[type].length; i < len; i++) {
			this.handlers[type][i].call();
		}
	};
};
